<?php
// initiate variables
$langpair = $_SESSION['langpair'];
$lowerlimit = 0;
$sort = array();
$setnonseleted1 = 0;
$setnonseleted2 = 0;
$setnonseleted3 = 0;
$setnonseleted4 = 0;
$setnonseleted5 = 0;
$setnonseleted6 = 0;
$break = 0;

// Box 1
if ( $resultconf1 > 0 )
{ 
$setnonseleted1 = 1;

// estimate limit-value of not selected
$i = 1;
$sql = "SELECT notselected FROM wordbox0 where boxid = 1 and customerid =". $customerid . " and langpairid =". $langpair . " order by notselected desc " ;
$db_res = mysql_query( $sql );
if ( ! $db_res ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res, MYSQL_ASSOC)) {
if ( $i == $resultconf1 ) { $limit = $row['notselected']; }
$i++;
}
if (isset($limit)) {  
// estimate and update words with notselected > $limit
$i = 1;
$sql1 = "SELECT * FROM wordbox0 where boxid = 1 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected > ". $limit ;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = ". $row['boxid'] . ", ";
	$sql1 .= " timestamp = current_timestamp ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); } 
$lowerlimit = $i;
$i++;
}

// estimate still open qty 
$upperlimit = $resultconf1 - $lowerlimit;


// shuffle the upperlimit-words
for ($x = 0; $x <= $limit; $x++)
{
$limit = $limit - $x;
$sql2 = "SELECT * FROM wordbox0 where boxid = 1 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected = ". $limit ;
$db_res2 = mysql_query( $sql2 );
if ( ! $db_res2 ) { die('Error query: ' . mysql_error()); }
$num_rows = mysql_num_rows($db_res2);
if ( $num_rows > 0 ) {
    while ($row = mysql_fetch_array( $db_res2, MYSQL_ASSOC)) {
        $sort[] = array($row['langpairid'],$row['langid'],$row['1word'],$row['word1']);
        }
$x = $limit + 1; // leave loop        
}
}

// shuffle values
shuffle ( $sort );

// read and update values
$i = 1;
foreach($sort as $werte_a1){

    if ( $i <= $upperlimit )
    {
        // update chosen words
	    $sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = 1, ";
	    $sql1 .= " timestamp = current_timestamp ";
        $sql1 .= " where customerid = ". $customerid ." ";
	    $sql1 .= " and boxid = 1 and langpairid = ". $werte_a1[0] ." and langid = ". $werte_a1[1] ." ";
	    $sql1 .= " and 1word = '". $werte_a1[2] ."' and word1 = '". $werte_a1[3] ."' ";
	    $db_upd = mysql_query( $sql1 );
        if ( ! $db_upd ) { die('Error query: ' . mysql_error()); } 
    }
    $i++;
    }
}
else
{
$break = 1; // stop it
} 
}
  
// Box 2
if ( $resultconf2 > 0 and $break == 0 )
{
$setnonseleted2 = 1;

// estimate limit-value of not selected
$i = 1;
$sql = "SELECT notselected FROM wordbox0 where boxid = 2 and customerid =". $customerid . " and langpairid =". $langpair . " order by notselected desc " ;
$db_res = mysql_query( $sql );
if ( ! $db_res ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res, MYSQL_ASSOC)) {
if ( $i == $resultconf2 ) { $limit = $row['notselected']; }
$i++;
}
if (isset($limit)) {

// estimate and update words with notselected > $limit
$i = 1;
$sql1 = "SELECT * FROM wordbox0 where boxid = 2 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected > ". $limit ;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = ". $row['boxid'] . ", ";
	$sql1 .= " timestamp = current_timestamp ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
$lowerlimit = $i;
$i++;
}

// estimate still open qty
$upperlimit = $resultconf2 - $lowerlimit;


// shuffle the upperlimit-words
for ($x = 0; $x <= $limit; $x++)
{
$limit = $limit - $x;
$sql2 = "SELECT * FROM wordbox0 where boxid = 2 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected = ". $limit ;
$db_res2 = mysql_query( $sql2 );
if ( ! $db_res2 ) { die('Error query: ' . mysql_error()); }
$num_rows = mysql_num_rows($db_res2);
if ( $num_rows > 0 ) {
    while ($row = mysql_fetch_array( $db_res2, MYSQL_ASSOC)) {
        $sort[] = array($row['langpairid'],$row['langid'],$row['1word'],$row['word1']);
        }
$x = $limit + 1; // leave loop
}
}

// shuffle values
shuffle ( $sort );

// read and update values
$i = 1;
foreach($sort as $werte_a1){

    if ( $i <= $upperlimit )
    {
        // update chosen words
	    $sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = 2, ";
	    $sql1 .= " timestamp = current_timestamp ";
        $sql1 .= " where customerid = ". $customerid ." ";
	    $sql1 .= " and boxid = 2 and langpairid = ". $werte_a1[0] ." and langid = ". $werte_a1[1] ." ";
	    $sql1 .= " and 1word = '". $werte_a1[2] ."' and word1 = '". $werte_a1[3] ."' ";
	    $db_upd = mysql_query( $sql1 );
        if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
    }
    $i++;
    }
}
else
{
$break = 1; // stop it
}
}

// Box 3
if ( $resultconf3 > 0 and $break == 0 )
{
$setnonseleted3 = 1;

// estimate limit-value of not selected
$i = 1;
$sql = "SELECT notselected FROM wordbox0 where boxid = 3 and customerid =". $customerid . " and langpairid =". $langpair . " order by notselected desc " ;
$db_res = mysql_query( $sql );
if ( ! $db_res ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res, MYSQL_ASSOC)) {
if ( $i == $resultconf3 ) { $limit = $row['notselected']; }
$i++;
}
if (isset($limit)) {

// estimate and update words with notselected < $limit
$i = 1;
$sql1 = "SELECT * FROM wordbox0 where boxid = 3 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected > ". $limit ;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = ". $row['boxid'] . ", ";
	$sql1 .= " timestamp = current_timestamp ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
$lowerlimit = $i;
$i++;
}

// estimate still open qty
$upperlimit = $resultconf3 - $lowerlimit;


// shuffle the upperlimit-words
for ($x = 0; $x <= $limit; $x++)
{
$limit = $limit - $x;
$sql2 = "SELECT * FROM wordbox0 where boxid = 3 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected = ". $limit ;
$db_res2 = mysql_query( $sql2 );
if ( ! $db_res2 ) { die('Error query: ' . mysql_error()); }
$num_rows = mysql_num_rows($db_res2);
if ( $num_rows > 0 ) {
    while ($row = mysql_fetch_array( $db_res2, MYSQL_ASSOC)) {
        $sort[] = array($row['langpairid'],$row['langid'],$row['1word'],$row['word1']);
        }
$x = $limit + 1; // leave loop
}
}

// shuffle values
shuffle ( $sort );

// read and update values
$i = 1;
foreach($sort as $werte_a1){

    if ( $i <= $upperlimit )
    {
        // update chosen words
	    $sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = 3, ";
	    $sql1 .= " timestamp = current_timestamp ";
        $sql1 .= " where customerid = ". $customerid ." ";
	    $sql1 .= " and boxid = 3 and langpairid = ". $werte_a1[0] ." and langid = ". $werte_a1[1] ." ";
	    $sql1 .= " and 1word = '". $werte_a1[2] ."' and word1 = '". $werte_a1[3] ."' ";
	    $db_upd = mysql_query( $sql1 );
        if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
    }
    $i++;
    }
}
else
{
$break = 1; // stop it
}
}


// Box 4
if ( $resultconf4 > 0 and $break == 0 )
{
$setnonseleted4 = 1;

// estimate limit-value of not selected
$i = 1;
$sql = "SELECT notselected FROM wordbox0 where boxid = 4 and customerid =". $customerid . " and langpairid =". $langpair . " order by notselected desc " ;
$db_res = mysql_query( $sql );
if ( ! $db_res ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res, MYSQL_ASSOC)) {
if ( $i == $resultconf4 ) { $limit = $row['notselected']; }
$i++;
}
if (isset($limit)) {

// estimate and update words with notselected > $limit
$i = 1;
$sql1 = "SELECT * FROM wordbox0 where boxid = 4 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected > ". $limit ;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = ". $row['boxid'] . ", ";
	$sql1 .= " timestamp = current_timestamp ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
$lowerlimit = $i;
$i++;
}

// estimate still open qty
$upperlimit = $resultconf4 - $lowerlimit;


// shuffle the upperlimit-words
for ($x = 0; $x <= $limit; $x++)
{
$limit = $limit - $x;
$sql2 = "SELECT * FROM wordbox0 where boxid = 4 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected = ". $limit ;
$db_res2 = mysql_query( $sql2 );
if ( ! $db_res2 ) { die('Error query: ' . mysql_error()); }
$num_rows = mysql_num_rows($db_res2);
if ( $num_rows > 0 ) {
    while ($row = mysql_fetch_array( $db_res2, MYSQL_ASSOC)) {
        $sort[] = array($row['langpairid'],$row['langid'],$row['1word'],$row['word1']);
        }
$x = $limit + 1; // leave loop
}
}

// shuffle values
shuffle ( $sort );

// read and update values
$i = 1;
foreach($sort as $werte_a1){

    if ( $i <= $upperlimit )
    {
        // update chosen words
	    $sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = 4, ";
	    $sql1 .= " timestamp = current_timestamp ";
        $sql1 .= " where customerid = ". $customerid ." ";
	    $sql1 .= " and boxid = 4 and langpairid = ". $werte_a1[0] ." and langid = ". $werte_a1[1] ." ";
	    $sql1 .= " and 1word = '". $werte_a1[2] ."' and word1 = '". $werte_a1[3] ."' ";
	    $db_upd = mysql_query( $sql1 );
        if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
    }
    $i++;
    }
}
else
{
$break = 1; // stop it
}
}


// Box 5
if ( $resultconf5 > 0 and $break == 0 )
{
$setnonseleted5 = 1;

// estimate limit-value of not selected
$i = 1;
$sql = "SELECT notselected FROM wordbox0 where boxid = 5 and customerid =". $customerid . " and langpairid =". $langpair . " order by notselected desc " ;
$db_res = mysql_query( $sql );
if ( ! $db_res ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res, MYSQL_ASSOC)) {
if ( $i == $resultconf5 ) { $limit = $row['notselected']; }
$i++;
}
if (isset($limit)) {

// estimate and update words with notselected > $limit
$i = 1;
$sql1 = "SELECT * FROM wordbox0 where boxid = 5 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected > ". $limit ;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = ". $row['boxid'] . ", ";
	$sql1 .= " timestamp = current_timestamp ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
$lowerlimit = $i;
$i++;
}

// estimate still open qty
$upperlimit = $resultconf5 - $lowerlimit;


// shuffle the upperlimit-words
for ($x = 0; $x <= $limit; $x++)
{
$limit = $limit - $x;
$sql2 = "SELECT * FROM wordbox0 where boxid = 5 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected = ". $limit ;
$db_res2 = mysql_query( $sql2 );
if ( ! $db_res2 ) { die('Error query: ' . mysql_error()); }
$num_rows = mysql_num_rows($db_res2);
if ( $num_rows > 0 ) {
    while ($row = mysql_fetch_array( $db_res2, MYSQL_ASSOC)) {
        $sort[] = array($row['langpairid'],$row['langid'],$row['1word'],$row['word1']);
        }
$x = $limit + 1; // leave loop
}
}

// shuffle values
shuffle ( $sort );

// read and update values
$i = 1;
foreach($sort as $werte_a1){

    if ( $i <= $upperlimit )
    {
        // update chosen words
	    $sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = 5, ";
	    $sql1 .= " timestamp = current_timestamp ";
        $sql1 .= " where customerid = ". $customerid ." ";
	    $sql1 .= " and boxid = 5 and langpairid = ". $werte_a1[0] ." and langid = ". $werte_a1[1] ." ";
	    $sql1 .= " and 1word = '". $werte_a1[2] ."' and word1 = '". $werte_a1[3] ."' ";
	    $db_upd = mysql_query( $sql1 );
        if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
    }
    $i++;
    }
}
else
{
$break = 1; // stop it
}
}


// Box 6
if ( $resultconf6 > 0 and $break == 0 )
{
$setnonseleted6 = 1;

// estimate limit-value of not selected
$i = 1;
$sql = "SELECT notselected FROM wordbox0 where boxid = 6 and customerid =". $customerid . " and langpairid =". $langpair . " order by notselected desc " ;
$db_res = mysql_query( $sql );
if ( ! $db_res ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res, MYSQL_ASSOC)) {
if ( $i == $resultconf6 ) { $limit = $row['notselected']; }
$i++;
}
if (isset($limit)) {

// estimate and update words with notselected > $limit
$i = 1;
$sql1 = "SELECT * FROM wordbox0 where boxid = 6 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected > ". $limit ;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = ". $row['boxid'] . ", ";
	$sql1 .= " timestamp = current_timestamp ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
$lowerlimit = $i;
$i++;
}

// estimate still open qty
$upperlimit = $resultconf6 - $lowerlimit;


// shuffle the upperlimit-words
for ($x = 0; $x <= $limit; $x++)
{
$limit = $limit - $x;
$sql2 = "SELECT * FROM wordbox0 where boxid = 6 and customerid =". $customerid . " and langpairid =". $langpair . " and notselected = ". $limit ;
$db_res2 = mysql_query( $sql2 );
if ( ! $db_res2 ) { die('Error query: ' . mysql_error()); }
$num_rows = mysql_num_rows($db_res2);
if ( $num_rows > 0 ) {
    while ($row = mysql_fetch_array( $db_res2, MYSQL_ASSOC)) {
        $sort[] = array($row['langpairid'],$row['langid'],$row['1word'],$row['word1']);
        }
$x = $limit + 1; // leave loop
}
}

// shuffle values
shuffle ( $sort );

// read and update values
$i = 1;
foreach($sort as $werte_a1){

    if ( $i <= $upperlimit )
    {
        // update chosen words
	    $sql1 = " update wordbox0 set boxid = 0, notselected = 0, boxbefore = 6, ";
	    $sql1 .= " timestamp = current_timestamp ";
        $sql1 .= " where customerid = ". $customerid ." ";
	    $sql1 .= " and boxid = 6 and langpairid = ". $werte_a1[0] ." and langid = ". $werte_a1[1] ." ";
	    $sql1 .= " and 1word = '". $werte_a1[2] ."' and word1 = '". $werte_a1[3] ."' ";
	    $db_upd = mysql_query( $sql1 );
        if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
    }
    $i++;
    }
}
else
{
$break = 1; // stop it
}
}

// notselected hochsetzen
if ( $setnonseleted1 = 1) {
$sql1 = "SELECT * FROM wordbox0 where boxid = 1 and customerid =". $customerid . " and langpairid =". $langpair;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set notselected = notselected + 1 ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
}}

if ( $setnonseleted2 = 1) {
$sql1 = "SELECT * FROM wordbox0 where boxid = 2 and customerid =". $customerid . " and langpairid =". $langpair ;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set notselected = notselected + 1 ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
}}

if ( $setnonseleted3 = 1) {
$sql1 = "SELECT * FROM wordbox0 where boxid = 3 and customerid =". $customerid . " and langpairid =". $langpair ;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set notselected = notselected + 1 ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
}}

if ( $setnonseleted4 = 1) {
$sql1 = "SELECT * FROM wordbox0 where boxid = 4 and customerid =". $customerid . " and langpairid =". $langpair ;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set notselected = notselected + 1 ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
}}

if ( $setnonseleted5 = 1) {
$sql1 = "SELECT * FROM wordbox0 where boxid = 5 and customerid =". $customerid . " and langpairid =". $langpair ;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set notselected = notselected + 1 ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
}}

if ( $setnonseleted6 = 1) {
$sql1 = "SELECT * FROM wordbox0 where boxid = 6 and customerid =". $customerid . " and langpairid =". $langpair ;
$db_res1 = mysql_query( $sql1 );
if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
while ($row = mysql_fetch_array( $db_res1, MYSQL_ASSOC)) {
    // update chosen words
	$sql1 = " update wordbox0 set notselected = notselected + 1 ";
    $sql1 .= " where customerid = ". $customerid ." ";
	$sql1 .= " and boxid = ". $row['boxid'] ." and langpairid = ". $row['langpairid'] ." and langid = ". $row['langid'] ." ";
	$sql1 .= " and 1word = '". $row['1word'] ."' and word1 = '". $row['word1'] ."' ";
	$db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) { die('Error query: ' . mysql_error()); }
}}

// initialize $num_rows
$sql = "SELECT * FROM wordbox0 where boxid = 0 and customerid =". $customerid . " and langpairid =". $langpair;
$db_res = mysql_query( $sql );
if ( ! $db_res ) { die('Error query: ' . mysql_error()); }
$num_rows = mysql_num_rows($db_res);

// initialize variables
$resultconf1 = 0;
$resultconf2 = 0;
$resultconf3 = 0;
$resultconf4 = 0;
$resultconf5 = 0;
$resultconf6 = 0;

?>